import MainMapViewUI = layaUI.main.MainMapViewUI;

class MainMapView extends MainMapViewUI{
    private _model:MapModel;

    constructor() {
        super();
        //title
        this.title1.style.align = "center";
        //内容
        this.content1.style.wordWrap = true;
        this.content1.style.leading = 20;
        //其他
        this.txtArea2.style.color = "#ffffff";
        this.txtArea2.style.leading = 10;
        this.txtNum.style.fontSize = 30;
        this.txtNum.style.color = "#ffffff";
        //数据
        this._model = MapModel.getInstance();
        //设置内容
        this.title1.innerHTML = LangUtils.getText(3);
        this.content1.innerHTML = LangUtils.getText(17);
        this.txtArea2.innerHTML = LangUtils.getText(4);
        this.txtReward.innerHTML = LangUtils.getText(26);
        //布局
        this.content1.y = this.title1.y + this.title1.contextHeight + 10;
        //语言
        LangUtils.setSkin(this.img1);
        LangUtils.setSkin(this.img2);
        LangUtils.setSkin(this.img3);
        //cdn加载
        ResUtils.setLoadSkin(this.imgBig2);
        ResUtils.setLoadSkin(this.imgBig3);
        ResUtils.setLoadSkin(this.imgBig4);
        ResUtils.setLoadSkin(this.imgBig5);
        ResUtils.setLoadSkin(this.imgBig6);
    }

    /**
     * 添加侦听
     */
    public addEvent():void{
        this._model.on(MapModel.INFO_CHANGE,this,this.onInfoChange);
        this.onInfoChange();
        if(this._model.nowCount == 0){
            MainMaskView.getInstance().open();
            this.map.mouseEnabled = false;
        }
    }

    /**
     * 移除侦听
     */
    public removeEvent():void{
        this._model.off(MapModel.INFO_CHANGE,this,this.onInfoChange);
        MainMaskView.getInstance().close();
    }

    //数据变更
    private onInfoChange():void{
        this.map.mouseEnabled = true;
        MainMaskView.getInstance().close();
        //刷新土地显示
        this.map.updateView();
        //刷新当前占领土地数量
        this.num.value = this._model.nowCount + "";
        this.txtNum.innerHTML = LangUtils.getText(25).replace("[1]",this._model.occupyNum+"");
    }
}